/*Scott Rogowski and Yipeng Huang*/
/*smr2167 yh2315*/

#include "vpi_user.h"
#include "misc.h"

int get_scalar_value(char *s)
{
	s_vpi_value v;
	vpiHandle h = vpi_handle_by_name(s, NULL);
	v.format = vpiScalarVal;
	vpi_get_value(h, &v);
	return v.value.scalar;
}

int get_int_value(char *s)
{
	s_vpi_value v;
	vpiHandle h = vpi_handle_by_name(s, NULL);
	v.format = vpiIntVal;
	vpi_get_value(h, &v);
	return v.value.integer;
}

void set_scalar_value(char *s, int port_value)
{
	//vpi_printf("%s %d\n", s, port_value);
	s_vpi_value v;
	vpiHandle h = vpi_handle_by_name(s, NULL);
	v.format = vpiScalarVal;
	v.value.scalar = port_value;
	vpi_put_value(h, &v, NULL, vpiNoDelay);
}

void set_int_value(char *s, int port_value)
{
	s_vpi_value v;
	vpiHandle h = vpi_handle_by_name(s, NULL);
	v.format = vpiIntVal;
	v.value.integer = port_value;
	vpi_put_value(h, &v, NULL, vpiNoDelay);
}

void set_u64_value(char *s, u64 port_value)
{
	// pg 163 Sutherland PLI -- Untested!
	s_vpi_value v;
	vpiHandle h = vpi_handle_by_name(s, NULL);
	v.format = vpiVectorVal;
	s_vpi_vecval vec;
	vec.aval = port_value & 0xffffffff;
	vec.bval = (port_value & 0xffffffff) >> 32;
	v.value.vector = &vec;
	vpi_put_value(h, &v, NULL, vpiNoDelay);
}
